'''
Created on Apr 15, 2012
TestCase ID: Ecom_5009
Description : Kiem thu chuc nang tao mot loai bai hoc moi
@author: Vu Dao
'''
import unittest
import time
import HTMLTestRunner
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.loginPageFunc import login
from Functions.administratorFunc import clickOnBtnCategories
from Functions.categoryFunc import clickOnNewCategory, createNewCategory,\
    isCategoryCreatedSuccessfully


username = readData("username")
password = readData("password")
categoryName = readData("categoriesLesson", index = 2)
class Ecom_5009(unittest.TestCase):

    
    def setUp(self):
        print "Buoc 1: Mo website"
        preCondition(self)

    def test_Ecom_5009(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username, password)
        
        print "Buoc 3: Click vao category"
        clickOnBtnCategories(self)
        
        print "Buoc 4: Click vao new category"
        clickOnNewCategory(self)
        
        print "Buoc 5: Tao mot category moi"
        createNewCategory(self,categoryName)
        
        print "Buoc 6: Kiem tra category da duoc tao thanh cong hay chua?"
        self.assertTrue(isCategoryCreatedSuccessfully(self,categoryName), "Failed: Category chua duoc tao thanh cong")
        print  "Passed: Category da duoc tao thanh cong"
    
    def tearDown(self):
        print "Buoc 7: Dong website"
        endCondition(self)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5009)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao mot loai bai hoc moi'
                    )
    runner.run(suite)